﻿Public Class MASOPERATE
    Private COPERATEID As Integer = Nothing
    Private COPERATENAME As String = Nothing
    Private CODEOPERATE As String = Nothing
    Private CLINIC As Integer = Nothing
    Private STATUS = Nothing
    '///////////////////////////////////////////
    Private OPERATENAME_EN As String = Nothing
    Private OPERATENAME_TH As String = Nothing
    Private CODE As String = Nothing
    Private OPERATID As Integer = Nothing
    Private CHOOSE = Nothing
    Private selectmasclsoperate = " SELECT `operatid` as 'รหัสหัตถการ',`code` AS 'CODE',`operatename_en` as 'ชื่อหัตถการภาษาอังกฤษ' ,`operatename_th` as 'ชื่อหัตถการภาษาไทย' FROM operatitem "
    Private SelectMasclinic = "SELECT `clinic` as 'รหัส',`cliniccode` as 'ชื่อย่อหน่วยงาน',`clinicname` as 'ชื่อหน่วยงาน',`coperateid`  AS 'COPERATEID' FROM masclinic ; "

    Dim connect As CONDB = CONDB.NewConnection()
    Property COPERATEID_() As Integer
        Get
            Return COPERATEID
        End Get
        Set(value As Integer)
            COPERATEID = value
        End Set
    End Property
    Property COPERATENAME_() As String
        Get
            Return COPERATENAME
        End Get
        Set(value As String)
            COPERATENAME = value
        End Set
    End Property
    Property CODEOPERATE_() As String
        Get
            Return CODEOPERATE
        End Get
        Set(value As String)
            CODEOPERATE = value
        End Set
    End Property
    Property CLINIC_() As Integer
        Get
            Return CLINIC
        End Get
        Set(value As Integer)
            CLINIC = value
        End Set
    End Property
    Property STATUS_() As Boolean
        Get
            Return STATUS
        End Get
        Set(value As Boolean)
            If value = True Then
                STATUS = 1
            Else
                STATUS = 0
            End If
        End Set
    End Property
    Property CHOOSE_() As Boolean
        Get
            Return CHOOSE
        End Get
        Set(value As Boolean)
            If value = True Then
                CHOOSE = 1
            Else
                CHOOSE = 0
            End If
        End Set
    End Property
    Property SelectMasclinic_() As String
        Get
            Return SelectMasclinic
        End Get
        Set(value As String)

        End Set
    End Property
    Property SelectMasclinic2_(id As String) As String
        Get
            Return "SELECT `clinic` as 'รหัส',`cliniccode` as 'ชื่อย่อหน่วยงาน',`clinicname` as 'ชื่อหน่วยงาน',`coperateid`,CASE WHEN(coperateid = " & id & ") THEN 1 ELSE 0 END AS 'เลือก'  FROM masclinic WHERE  `coperateid` in ('" & id & "','') OR `coperateid` IS NULL;"
        End Get
        Set(value As String)

        End Set
    End Property
    Property selectmasclsoperate_() As String
        Get
            Return selectmasclsoperate
        End Get
        Set(value As String)

        End Set
    End Property
    Property OPERATID_() As Integer
        Get
            Return OPERATID
        End Get
        Set(value As Integer)
            OPERATID = value
        End Set
    End Property
    Property OPERATENAME_TH_() As String
        Get
            Return OPERATENAME_TH
        End Get
        Set(value As String)
            OPERATENAME_TH = value
        End Set
    End Property

    Property OPERATENAME_EN_() As String
        Get
            Return OPERATENAME_EN
        End Get
        Set(value As String)
            OPERATENAME_EN = value
        End Set
    End Property
    Property CODE_() As Integer
        Get
            Return CODE
        End Get
        Set(value As Integer)
            CODE = value
        End Set
    End Property
    Public Sub insertMasclsoperate()
        If TypeOf COPERATENAME Is String And TypeOf CODEOPERATE Is String Then
            'MsgBox("SELECT `COPERATEID`,`CODE` FROM MASCLSOPERATE WHERE  `COPERATEID` = '" & COPERATEID & "' and `CODEOPERATE` = '" & CODEOPERATE & "'  ")
            If connect.GetTable("SELECT `COPERATENAME`,`CODE` FROM MASCLSOPERATE WHERE  `COPERATENAME` = '" & COPERATENAME & "' and `CODE` = '" & CODEOPERATE & "'  ").Rows.Count > 0 Then
                MsgBox("มีข้อมูลส่วนนี้อยู่ในระบบแล้ว", MsgBoxStyle.Critical)
            Else
                connect = CONDB.NewConnection()
                connect.BeginTrans()
                Try
                    'Dim productCode As Integer
                    'productCode = connect.ExecuteScalar("INSERT INTO MASPRODUCT (`PRDCAT`, `PRDNAME`, `CCODE`, `RCODE`,`OPDPRC`,`IPDPRC`) VALUES ('3', '" & OPERATENAME_EN & "', '" & CCODE & "', '" & RCODE & "','" & OPDPRC & "','" & IPDPRC & "'); SELECT LAST_INSERT_ID();")
                    Dim sql As String
                    sql = "INSERT INTO MASCLSOPERATE"
                    sql += "(`COPERATENAME`,`CODE`,`STATUS`,`CLINIC`)"
                    sql += "VALUES ("
                    sql += "'" & COPERATENAME & "',"
                    sql += "'" & CODEOPERATE & "',"
                    sql += "'" & STATUS & "',"
                    If CLINIC = 0 Then
                        sql += "Null);"
                    Else
                        sql += "'" & CLINIC & "');"
                    End If
                    connect.ExecuteNonQuery(sql)
                    connect.CommitTrans()
                    MsgBox("ท่านได้ทำการเพิ่มข้อมูลเรียบร้อยแล้ว", MsgBoxStyle.Information)
                Catch ex As Exception
                    connect.RollbackTrans()
                    MsgBox(ex.ToString)
                Finally
                    connect.Dispose()
                End Try
            End If
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร", MsgBoxStyle.Critical)
        End If
    End Sub

    Public Sub editMasclsoperate()
        If TypeOf COPERATENAME Is String And TypeOf CODEOPERATE Is String Then
            connect = CONDB.NewConnection()
            connect.BeginTrans()
            Try
                Dim sql As String
                sql = "UPDATE MASCLSOPERATE SET"
                sql += "`COPERATENAME` = '" & COPERATENAME & "',"
                sql += "`CODE` = '" & CODEOPERATE & "',"
                sql += "`STATUS` = '" & STATUS & "',"
                sql += "`CLINIC` = '" & CLINIC & "'"
                sql += "WHERE `COPERATEID` = '" & COPERATEID & "';"
                connect.ExecuteNonQuery(sql)
                connect.CommitTrans()
                MsgBox("ท่านได้ทำการแก้ไขข้อมูลเรียบร้อยแล้ว", MsgBoxStyle.Information)
            Catch ex As Exception
                connect.RollbackTrans()
                MsgBox(ex.ToString)
            Finally
                connect.Dispose()
            End Try
        Else
            MsgBox("โปรดกรุณาระบุข้อมูลให้ถูกต้อง ต้องเป็นตัวอักษร", MsgBoxStyle.Critical)
        End If
    End Sub
End Class
